package com.cyt.web.controller.website;

import cn.hutool.core.util.StrUtil;
import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.BaseController;
import com.cyt.website.model.vo.WebsiteBannerVo;
import com.cyt.website.service.WebsiteBannerService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 官网banner图管理-官网banner图管理控制层
 *
 * @author 聪聪
 * @date 2019-8-12 14:23:55
 */
@RestController
public class WebsiteBannerController extends BaseController {

    @Resource
    private WebsiteBannerService websiteBannerService;

    /**
     * 统一跳转
     *
     * @param model 数据模型
     * @return Model
     * @author 聪聪
     * @date 2019-8-12 14:23:55
     */
    @RequestMapping("/website/websitebanner/*")
    public Model goPage(Model model) {
        return model;
    }

    /**
     * 分页查询
     *
     * @param websiteBannerVo 接受参数对象
     * @param page 当前页面
     * @param limit 页面数量
     * @return ReturnResult
     * @author 聪聪
     * @date 2019-8-12 14:23:55
     */
    @BaseLog(module = "官网banner图管理", classz = "官网banner图管理", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/website/websitebanner/page", method = RequestMethod.POST)
    public ReturnResult page(WebsiteBannerVo websiteBannerVo, int page, int limit) {
        return websiteBannerService.page(websiteBannerVo, page, limit);
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param id 主键
     * @return ReturnResult
     * @author 聪聪
     * @date 2019-8-12 14:23:55
     */
    @BaseLog(module = "官网banner图管理", classz = "官网banner图管理", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/website/websitebanner/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id) {
        ModelAndView view = new ModelAndView("/website/websitebanner/websiteBannerEdit");
        if (StrUtil.isNotEmpty(id)) {
            view.addObject("websiteBanner", websiteBannerService.selectByPrimaryKey(id));
        }
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request 请求对象
     * @param websiteBannerVo 接受参数对象
     * @return ReturnResult
     * @author 聪聪
     * @date 2019-8-12 14:23:55
     */
    @BaseLog(module = "官网banner图管理", classz = "官网banner图管理", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/website/websitebanner/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, WebsiteBannerVo websiteBannerVo) {
        return websiteBannerService.addOrUpdate(websiteBannerVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request 请求对象
     * @param websiteBannerVo 接受参数对象
     * @return ReturnResult
     * @author 聪聪
     * @date 2019-8-12 14:23:55
     */
    @BaseLog(module = "官网banner图管理", classz = "官网banner图管理", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/website/websitebanner/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, WebsiteBannerVo websiteBannerVo) {
        return websiteBannerService.remove(websiteBannerVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件物理删除
     *
     * @param request 请求对象
     * @param websiteBannerVo 接受参数对象
     * @return ReturnResult
     * @author 聪聪
     * @date 2019-8-12 14:23:55
     */
    @BaseLog(module = "官网banner图管理", classz = "官网banner图管理", methods = "物理删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/website/websitebanner/delete", method = RequestMethod.GET)
    public ReturnResult delete(HttpServletRequest request, WebsiteBannerVo websiteBannerVo) {
        return websiteBannerService.delete(websiteBannerVo, acceptCurrentUser(request));
    }

    /**
     * 发布/取消发布
     *
     * @param request  请求对象
     * @param bannerVo 接受参数对象
     * @return ReturnResult
     * @author 聪聪
     * @date 2019-8-12 14:23:55
     */
    @BaseLog(module = "官网banner图管理", classz = "轮播图", methods = "发布/取消发布", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/website/websitebanner/updateStatus", method = RequestMethod.POST)
    public ReturnResult updateStatus(HttpServletRequest request, WebsiteBannerVo bannerVo) {
        return websiteBannerService.updateStatus(bannerVo, acceptCurrentUser(request));
    }
}